<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑角色</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var name = new Ext.form.TextField({
          fieldLabel: '名称',
          allowBlank: false,
          name: 'name',
          anchor: '100%'
        });

        var financialManagement = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '是否有财务权',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          name:'financial_management',
          columns : 2,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'financial_management'},
            {boxLabel:'否',inputValue:'否',name:'financial_management'}
          ]
        });

        var unsafeDiscountAudit = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '非安全折扣审批',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 2,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'unsafe_discount_audit'},
            {boxLabel:'否',inputValue:'否',name:'unsafe_discount_audit',checked:true}
          ]
        });
        
        //跨部门销售订单查询能力
        var crossDeptSaleOrderQuery = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '是否可以跨部门查询销售订单',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          name:'cross_dept_sale_order_query',
          columns : 2,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'cross_dept_sale_order_query'},
            {boxLabel:'否',inputValue:'否',name:'cross_dept_sale_order_query'}
          ]
        });

        //最低折扣权限
        var discount = new Ext.form.NumberField({
          fieldLabel: '最低折扣',
          name:'discount',
          allowBlank: false,
          allowDecimals: true,
          allowNegative: false
        })
        
        var desc = new Ext.form.TextArea({
          fieldLabel: '备注',
          allowBlank: false,
          height:50,
          name: 'description',
          anchor: '100%'
        });

        var roleId = new Ext.form.Hidden({
          name: 'id',
          value: '<%=params[:id]%>'
        });
        
        //提交按钮
        var editRoleButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            editRoleButton.setDisabled(true);
            if (editRoleFormPanel.form.isValid()) {
              editRoleFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    editRoleWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  editRoleButton.enable();
                },
                failure: function(result, request){
                  editRoleButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              editRoleButton.enable();
              
            }
          }
        })
        
        var editRoleFormPanel = new Ext.form.FormPanel({
          labelWidth: 165,
          width: 400,
          labelAlign: 'right',
          frame : true,
          url: '/admin/updateRole',
          method: 'GET',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'name'
            }, {
              name: 'financial_management'
            }, {
              name: 'cross_dept_sale_order_query'
            }, {
              name: 'unsafe_discount_audit'
            }, {
              name: 'discount'
            }, {
              name: 'description'
            }]),
          items: [name,financialManagement,unsafeDiscountAudit,crossDeptSaleOrderQuery,discount,desc,roleId],
          buttons: [editRoleButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editRoleWin.destroy();
              }
            }]
        });

        editRoleFormPanel.form.load({
          url: '/admin/getRoleById?id=' + roleId.getValue(),
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editRoleFormPanel.render('edit_role_form');
      })
    </script>
    <div id="edit_role_form"></div>
  </body>
</html>
